import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
    routes: [
        {
            path: '/',
            component: () => import(/* webpackChunkName: "home" */ 'h5/page/home'),
            redirect: '/applyForm', // /applyForm
            meta: {
                title: '首页',
            },
        },
        {
            path: '/applyForm',
            component: () => import(/* webpackChunkName: "applyForm" */ 'h5/page/applyForm/applyForm'),
            meta: {
                title: '普通高中生特长生报名单',
            },
        },

        {
            path: '/success',
            component: () => import(/* webpackChunkName: "success" */ 'h5/page/success.vue'),
            meta: {
                title: '成功',
            },
        },

        {
            path: '/login',
            component: () => import('h5/page/login'),
            meta: {
                title: '登录',
            },
        },
        {
            path: '/404',
            component: () => import('h5/page/404'),
            meta: {
                title: '页面不存在',
            },
        },
        {
            path: '*',
            redirect: '/404',
        },
    ],
})

// 导航守卫
// 判断用户是否登录，添加前置导航守卫
router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title}`
    next()
    // const sign = localStorage.getItem('sign');
    // if (sign) {
    //     next()
    // } else {
    //     if (to.path === '/login') { // 如果是登录页
    //         next();
    //     } else {
    //         next({ path: '/login' })
    //     }
    // }
})
export default router
